package logic;

public class PasswordCheck implements I_PasswordCheckable {

	@Override
	public boolean checkPassword(String password) {
		int passwordLenght = password.length();
		if(checkPasswordLenght(passwordLenght) == true){
			if(checkTwoUpperCaseChar(password, passwordLenght) == true){
				if(checkTwoLowerCaseChar(password, passwordLenght) == true){
					if(checkTwoDigitalChar(password, passwordLenght) == true){
						if(checkTwoSpecialChar(password, passwordLenght) == true){
							return true;
						}
					}
				}
			}
		}
		return false;
	}

	public boolean checkPasswordLenght(int passwordLenght) {
		if(passwordLenght > 7){
			return true;
		}
		return false;
	}

	@Override
	public boolean checkTwoUpperCaseChar(String password, int passwordLength) {
		int countUpperCase = 0;
		for(int character = 0; character < passwordLength; character ++){
			if(Character.isUpperCase(password.charAt(character))){
				countUpperCase++;
			}
		}
		if(countUpperCase > 1){
			return true;
		}
		return false;
	}

	@Override
	public boolean checkTwoLowerCaseChar(String password, int passwordLength) {
		int countLowerCase = 0;
		for(int character = 0; character < passwordLength; character ++){
			if(Character.isLowerCase(password.charAt(character))){
				countLowerCase++;
			}
		}
		if(countLowerCase > 1){
			return true;
		}
		return false;
	}

	@Override
	public boolean checkTwoDigitalChar(String password, int passwordLenght) {
		int countDigitalCase = 0;
		for(int character = 0; character < passwordLenght; character ++){
			if(Character.isDigit(password.charAt(character))){
				countDigitalCase++;
			}
		}
		if(countDigitalCase > 1){
			return true;
		}
		return false;
	}

	@Override
	public boolean checkTwoSpecialChar(String password, int passwordLenght) {
		int countDigitalCase = 0;
		for(int character = 0; character < passwordLenght; character ++){
			if(!Character.isDigit(password.charAt(character)) && !Character.isUpperCase(password.charAt(character)) && !Character.isLowerCase(password.charAt(character))){
				countDigitalCase++;
			}
		}
		if(countDigitalCase > 1){
			return true;
		}
		return false;
	}

}
